/*******************************************************************************
 * StandardAudioLibrary.h
 *
 * Copyright (c) 2012, Varuna L Amachi. All rights reserved.
 *
 * This program/library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This program/library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301  USA
 ******************************************************************************/

#ifndef STANDARDAUDIOLIBRARY_H
#define STANDARDAUDIOLIBRARY_H

#include "core/components/AbstractAudioLibrary.h"

namespace Tanyatu
{
namespace Component
{
class TANYATU_CORE_EXPORT StandardAudioLibrary : public AbstractAudioLibrary
{
    Q_OBJECT

public:
    void add( Tanyatu::Model::StoredAudio *item );

    void add( QList< Tanyatu::Model::StoredAudio *>& items);

    void remove( QString id );

    void remove( QList< QString > ids);

    void rescan();

    void setRating( QString id, Tanyatu::Model::MediaRating rating );

    void updateItem( QString id, Tanyatu::Model::AudioTrack &updateInfo );

    void onItemPlaybackStarted( Tanyatu::Model::MediaItem *item );

    void onItemPlaybackFinished( Tanyatu::Model::MediaItem *item );

    void tagItem( QString id, QString tag );

    void removeItemTag( QString id, QString tag );

    void deleteAll();

    explicit StandardAudioLibrary(QObject *parent = 0);

    virtual ~StandardAudioLibrary();

    quint32 itemCount() const;

    bool hasItem( const QString itemId );

    Model::StoredAudio *item( QString id ) const;

    quint32 items( QList< QString > &ids, QHash< QString,
                                        Model::StoredAudio *>& itemsOut ) const;

    quint32 items( QList< QString >& ids,
                           QList< Model::MediaItem *> &itemsOut ) const;

    quint32 items( QList< QString >& ids,
                           QList< Model::StoredAudio *> &itemsOut ) const;

    Model::StoredAudio *item( int index ) const;

    quint32 allItems( QList< Tanyatu::Model::StoredAudio *> &out ) const;

    int rowCount(const QModelIndex &parent) const;

    int columnCount(const QModelIndex &parent) const;

    QVariant data(const QModelIndex &index, int role) const;

    QVariant headerData(int section,
                        Qt::Orientation orientation, int role) const;

    QModelIndex index(int row, int column, const QModelIndex &parent) const;

    QModelIndex parent(const QModelIndex &child) const;

    bool hasChildren(const QModelIndex &parent) const;

    Qt::ItemFlags flags(const QModelIndex &index) const;

    bool setData(const QModelIndex &index, const QVariant &value, int role);

    void setValid(bool value);

    QString uniqueName() const;

    QString module()  const;

    QString displayName() const;

    bool init();

    static QString COMPONENT_NAME;

    static QString COMPONENT_MODULE;

protected:

    QHash< QString, Model::StoredAudio *> m_tracks;

    QList< Model::StoredAudio *> *m_itemList;

    bool m_valid;

    void clear();
};
}
}

#endif // STANDARDAUDIOLIBRARY_H
